class subscriber extends uvm_subscriber #(i2c_trans);
    `uvm_component_utils(subscriber)

    uvm_analysis_imp #(i2c_trans,subscriber) analysis_export;
    i2c_trans pkt;

    bit sda;
    bit scl;

    real coverage_result;
    static int pkts_checked = 0;

    covergroup i2c_cov;
        coverpoint sda
            {bins csda[]={0, 1};}
        coverpoint scl;
        cross      sda,scl;
    endgroup

    function new(string name, uvm_component parent);
        super.new(name, parent);
        `uvm_info("TRACE", $sformatf("%m"), UVM_HIGH)
        i2c_cov = new();
    endfunction

    virtual function void build_phase(uvm_phase phase);
        super.build_phase(phase);
        analysis_export = new("analysis_export",this);
    endfunction

    virtual function void write(apb_trans pkt);
        `uvm_info("TRACE", $sformatf("%m"), UVM_HIGH)
        this.sda = pkt.sda;
        this.write = (pkt.kind==i2c_trans::WRITE)?1:0;
        i2c_cov.sample();
        coverage_result = $get_coverage();
        $display("[NOTE]%t Packet #%0d coverage = %3.2f",$realtime,pkts_checked++,coverage_result);
    endfunction

endclass